/**
 * 0_hello_world
 */
#include <stdio.h>
#include <cuda_runtime.h>

__global__ void hello_world(void) {
    printf("GPU: Hello world!\n");
}

int main() {
    printf("CPU: Hello world!\n");
    hello_world<<<1, 10>>>();

    // Check for any errors launching the kernel
    cudaError_t err = cudaGetLastError();
    if (err != cudaSuccess) {
        fprintf(stderr, "Failed to launch hello_world kernel (error code %s)!\n", cudaGetErrorString(err));
        return -1;
    }

    // Ensure the GPU has finished executing the kernel
    err = cudaDeviceSynchronize();
    if (err != cudaSuccess) {
        fprintf(stderr, "Failed to synchronize (error code %s)!\n", cudaGetErrorString(err));
        return -1;
    }

    // Reset the device
    cudaDeviceReset();

    return 0;
}